package edu.mse.camel.client.whiteboard.gef.ui.properties;

import java.util.List;

import org.eclipse.ui.views.properties.TextPropertyDescriptor;

import edu.mse.camel.client.whiteboard.gef.whiteboard.Shape;

public class ShapePropertySource extends AbstractPropertySource {
	
	private static final String ID_X = "X";
	private static final String ID_Y = "Y";
	private static final String ID_WIDTH = "Width";
	private static final String ID_HEIGHT = "Height";
	
	public ShapePropertySource(Object model) {
		super(model);
	}
	
	private Shape getShape() {
		return (Shape) getModel();
	}
	
	public void createPropertyDescriptors(List descriptors) {
		descriptors.add(new TextPropertyDescriptor(ID_X, ID_X));
		descriptors.add(new TextPropertyDescriptor(ID_Y, ID_Y));
		descriptors.add(new TextPropertyDescriptor(ID_WIDTH, ID_WIDTH));
		descriptors.add(new TextPropertyDescriptor(ID_HEIGHT, ID_HEIGHT));
	}
	
	public Object getPropertyValue(Object id) {
		if(id == ID_X) {
			return Integer.toString(getShape().getX());
		}
		if(id == ID_Y) {
			return Integer.toString(getShape().getY());
		}
		if(id == ID_WIDTH) {
			return Integer.toString(getShape().getWidth());
		}
		if(id == ID_HEIGHT) {
			return Integer.toString(getShape().getHeight());
		}
		return null;
	}
	
	public void setPropertyValue(Object id, Object value) {
		if (id == ID_X) {
			getShape().setX(Integer.parseInt(value.toString()));
		} else if (id == ID_Y) {
			getShape().setY(Integer.parseInt(value.toString()));
		} else if (id == ID_WIDTH) {
			getShape().setWidth(Integer.parseInt(value.toString()));
		} else if(id == ID_HEIGHT) {
			getShape().setHeight(Integer.parseInt(value.toString()));
		}
	}
	
}
